Note
Click here to download the full example code
Callosal bundles using AFQ API¶
An example using the AFQ API to find callosal bundles using the templates from: http://hdl.handle.net/1773/34926
import os.path as op
import plotly
from AFQ import api
from AFQ.definitions.mask import RoiMask
import AFQ.data as afd
Get some example data¶
Retrieves Stanford HARDI dataset.
afd.organize_stanford_data(clear_previous_afq=True)
Set tractography parameters (optional)¶
We make this tracking_params which we will pass to the AFQ object which specifies that we want 100,000 seeds randomly distributed in the ROIs of every bundle.
We only do this to make this example faster and consume less space.
tracking_params = dict(seed_mask=RoiMask(),
n_seeds=10000,
random_seeds=True,
rng_seed=42)
Initialize an AFQ object:¶
We specify bundle_info as the callosal bundles only (api.CALLOSUM_BUNDLES). If we want to segment both the callosum and the other bundles, we would pass api.CALLOSUM_BUNDLES + api.BUNDLES instead. This would tell the AFQ object to use bundles from both the standard and callosal templates.
myafq = api.AFQ(bids_path=op.join(afd.afq_home,
'stanford_hardi'),
dmriprep='vistasoft',
bundle_info=api.CALLOSUM_BUNDLES,
tracking_params=tracking_params,
viz_backend='plotly_no_gif')
# Calling export all produces all of the outputs of processing, including
# tractography, scalar maps, tract profiles and visualizations:
myafq.export_all()
Out:
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
0%| | 0/4966 [00:00<?, ?it/s]
0%| | 2/4966 [00:00<04:33, 18.15it/s]
0%| | 4/4966 [00:04<1:54:46, 1.39s/it]
0%| | 6/4966 [00:04<1:04:58, 1.27it/s]
16%|#5 | 782/4966 [00:05<00:13, 309.22it/s]
31%|###1 | 1550/4966 [00:05<00:04, 704.17it/s]
42%|####1 | 2062/4966 [00:05<00:02, 1008.90it/s]
62%|######2 | 3086/4966 [00:05<00:01, 1841.67it/s]
83%|########2 | 4110/4966 [00:05<00:00, 2534.10it/s]
100%|##########| 4966/4966 [00:05<00:00, 900.11it/s]
0%| | 0/4966 [00:00<?, ?it/s]
31%|### | 1532/4966 [00:00<00:00, 13666.59it/s]
82%|########2 | 4092/4966 [00:00<00:00, 14411.91it/s]
100%|##########| 4966/4966 [00:00<00:00, 17352.90it/s]
0%| | 0/4966 [00:00<?, ?it/s]
15%|#5 | 764/4966 [00:00<00:00, 6717.27it/s]
41%|####1 | 2044/4966 [00:00<00:00, 7362.08it/s]
82%|########2 | 4092/4966 [00:00<00:00, 8351.47it/s]
100%|##########| 4966/4966 [00:00<00:00, 9815.12it/s]
0%| | 0/4966 [00:00<?, ?it/s]
21%|## | 1020/4966 [00:00<00:00, 10197.17it/s]
62%|######1 | 3068/4966 [00:00<00:00, 13941.79it/s]
100%|##########| 4966/4966 [00:00<00:00, 16589.06it/s]
0%| | 0/4966 [00:00<?, ?it/s]
21%|## | 1020/4966 [00:00<00:00, 7306.44it/s]
41%|####1 | 2044/4966 [00:00<00:00, 8014.17it/s]
82%|########2 | 4092/4966 [00:00<00:00, 8620.51it/s]
100%|##########| 4966/4966 [00:00<00:00, 10214.89it/s]
0%| | 0/4966 [00:00<?, ?it/s]
10%|# | 508/4966 [00:00<00:01, 3489.31it/s]
21%|## | 1020/4966 [00:00<00:01, 3353.44it/s]
41%|####1 | 2044/4966 [00:00<00:00, 3548.09it/s]
51%|#####1 | 2556/4966 [00:00<00:00, 3339.56it/s]
62%|######1 | 3068/4966 [00:00<00:00, 3277.06it/s]
72%|#######2 | 3580/4966 [00:01<00:00, 3311.11it/s]
82%|########2 | 4092/4966 [00:01<00:00, 3165.77it/s]
93%|#########2| 4604/4966 [00:01<00:00, 3037.05it/s]
100%|##########| 4966/4966 [00:01<00:00, 3469.09it/s]
0%| | 0/4966 [00:00<?, ?it/s]
21%|## | 1020/4966 [00:00<00:00, 8546.96it/s]
41%|####1 | 2044/4966 [00:00<00:00, 8788.34it/s]
82%|########2 | 4092/4966 [00:00<00:00, 8868.16it/s]
100%|##########| 4966/4966 [00:00<00:00, 10707.90it/s]
0%| | 0/4966 [00:00<?, ?it/s]
21%|## | 1020/4966 [00:00<00:00, 7769.18it/s]
41%|####1 | 2044/4966 [00:00<00:00, 8466.16it/s]
82%|########2 | 4092/4966 [00:00<00:00, 9431.96it/s]
100%|##########| 4966/4966 [00:00<00:00, 11094.58it/s]
Visualizing bundles and tract profiles:¶
This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.
bundle_html = myafq.all_bundles_figure
plotly.io.show(bundle_html["01"])
Total running time of the script: ( 13 minutes 32.703 seconds)